import React, { Component } from 'react'
import axios from 'axios'

export default class MyData extends Component {
  state = {
    banner: []
  }

  getBannersData = async () => {
    const res = await axios.get('http://81.69.235.62:3000/app/banners')

    if (res.data.code === 200) {
      this.setState({
        banner: res.data.result
      })
    }
  }

  componentDidMount() {
    this.getBannersData()
  }

  render() {
    return (
      <div>
        <h3>React 请求 ajsx 流程</h3>
        <div>
          {
            this.state.banner.map((item,index) => {
              return (
                <img style={{ width: 150, height: 150, borderRadius: 15, margin: 15 }} src={item.imgurl.replace(/public/, 'http://81.69.235.62:3000')} alt="" key={index} />
              )
            })
          }
        </div>
      </div>
    )
  }
}
